package com.yywq.controller;

import com.yywq.pojo.Address;
import com.yywq.pojo.model.UserToken;
import com.yywq.response.CommonReturnType;
import com.yywq.service.impl.AddressServiceImpl;
import com.yywq.utils.MyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: 吴磊
 * @program: yywq_parent
 * @create: 2021-04-15 19:45
 */
@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private AddressServiceImpl addressService;

    @Autowired
    private MyUtil myUtil;

    /**
     * 获取用户Address
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    private CommonReturnType getUserAddress() throws Exception {
        UserToken userToken = myUtil.getUserToken();
        String id = userToken.getId();
        List<Address> addressByUserId = addressService.getAddressByUserId(id);
        return CommonReturnType.create(addressByUserId);
    }


}
